import { Button, Textarea, View } from '@tarojs/components';
import './index.scss'
import '../../style/title.scss'
import '../../style/button.scss'
import { useContext, useState } from 'react';
import Taro, { useLoad } from '@tarojs/taro';
import { InformedConsentContext } from '../../configProvider/informedConsent';

const InformedConsent: React.FC<null> = () => {
  const informedContent = useContext(InformedConsentContext)
  const [leftTime, setLeftTime] = useState('(5)');
  const decrease = async () => {
    for (let i = 5; i > 0; i--) {
      await new Promise((resolve) => {
        setTimeout(resolve, 1000)
      }).then(() => {
        setLeftTime(`(${i - 1})`)
        console.log('倒计时', `${i}=>${i - 1}`)
      })
    }
    setLeftTime('')
  }
  useLoad(() => {
    decrease();
  })

  const agreed = () => {
    // if (leftTime) {
    //   return
    // }
    Taro.navigateBack();
    Taro.navigateTo({ url: '../consultantList/index' });
  }
  return <>
    <View className='common-title'>知情者同意书</View>
    <Textarea className='informed-consent-content' value={informedContent.content} maxlength={1000}></Textarea>

    <Button className='common-button' onClick={agreed} >我同意{leftTime}</Button>
  </>
}
export default InformedConsent;
